package com.lagou.web;


import com.lagou.entity.User;

import com.lagou.service.UserServiceImplement;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

import java.sql.SQLException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class AddServlet extends HttpServlet {


    @Override

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req, resp);

    }


    @Override

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 中文乱码

        req.setCharacterEncoding("UTF-8");


        // 1. 接收参数

        String sNo= req.getParameter("sNo");

        String username = req.getParameter("name");

        String password = req.getParameter("password");

        String sex = req.getParameter("sex");

        String birthday = req.getParameter("birthday");

        // 2.封装参数

        User user = new User();

        user.setsNo(sNo);

        user.setName(username);

        user.setPassword(password);

        user.setSex(sex);

        user.setBirthday(birthday);

        // 3.调用方法

        try {

            new UserServiceImplement().addUser(user);

        } catch (SQLException e) {

            e.printStackTrace();

        }

        // 4.输出

        resp.getWriter().write("add success..");

    }

}